package com.sanjiahantang.youjiaclient.module.common.views.impl;

import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.sanjiahantang.uilibrary.utils.QRCodeUtil;
import com.sanjiahantang.youjiaclient.R;
import com.sanjiahantang.youjiaclient.config.SPConfig;
import com.sanjiahantang.youjiaclient.config.StaticValue;
import com.sanjiahantang.youjiaclient.utils.SPUtils;


/**
 * Created by admin on 2017/7/30.
 */

public class ShareSqcodeActivity extends AppCompatActivity implements View.OnClickListener,StaticValue {

    TextView tv_title, tv_qrcode;
    ImageView iv_back, iv_qrcode;
    private static int TYPE_HIDDEN = 1;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        String code = getIntent().getStringExtra("QRCODE");
        String title = getIntent().getStringExtra(KEY_TITLE);
        setContentView(R.layout.activity_share_sq);
        tv_title = (TextView) findViewById(R.id.title);
        iv_back = (ImageView) findViewById(R.id.back);
        iv_back.setOnClickListener(this);
        tv_qrcode = (TextView) findViewById(R.id.qrcode);
        iv_qrcode = (ImageView) findViewById(R.id.iv_qrcode);
        tv_qrcode.setText(code);
        if (TextUtils.isEmpty(title)){
            tv_title.setText("我的二维码");
        }else{
            tv_title.setText(title);
        }

        if (getIntent().getIntExtra(KEY_TYPE,-1) == TYPE_HIDDEN){
            findViewById(R.id.tvInfo).setVisibility(View.INVISIBLE);
            findViewById(R.id.llNo).setVisibility(View.INVISIBLE);
        }

        if(code==null){
            code= SPUtils.get(this, SPConfig.PHONE,"").toString();
        }
        Bitmap bitmap= QRCodeUtil.createQRImage(code,350,350);
        iv_qrcode.setImageBitmap(bitmap);

    }

    @Override
    public void onClick(View view) {
        finish();
    }

    public static void openQRPage(Context context,String qrCode,String title){
        Intent mIntent = new Intent(context,ShareSqcodeActivity.class);
        mIntent.putExtra("QRCODE",qrCode);
        mIntent.putExtra(KEY_TITLE,title);
        mIntent.putExtra(KEY_TYPE,TYPE_HIDDEN);
        context.startActivity(mIntent);
    }
}
